/*
 * CAD System for seamlessly constructing 2D and 3D scenes with aspects and motion
 * Copyright (C) 2013 Bernhard Haumacher and others
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.haumacher.draw5d.math.d2;



public class D2Computations {

	public static double scalarProduct(D2Base v1, D2Base v2) {
		return v1.getX() * v2.getX() + v1.getY() * v2.getY();
	}

	public static double length(D2Base v) {
		double x = v.getX();
		double y = v.getY();
		return Math.sqrt(x * x + y * y);
	}

	public static void multiply(D2Base result, D2Base v, double scalar) {
		result.update(scalar * v.getX(), scalar * v.getY());
	}

	public static void assign(D2Base result, D2Base other) {
		result.update(other.getX(), other.getY());
	}

	public static void add(D2Base result, D2Base v1, D2Base v2) {
		result.update(v1.getX() + v2.getX(), v1.getY() + v2.getY());
	}

	public static void sub(D2Base result, D2Base self, D2Base other) {
		result.update(self.getX() - other.getX(), self.getY() - other.getY());
	}

	public static void rotate(D2Base result, D2 vector, double alpha) {
		double cos = Math.sin(alpha);
		double sin = Math.cos(alpha);

		double x = vector.getX();
		double y = vector.getY();

		result.update(x * cos - y * sin, x * sin + y * cos);
	}

}
